/**
 * 
 */
package NewGW;

import java.util.ArrayList;

import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;

import gnu.io.CommPortIdentifier;

/**
 * 
 */
public class PortList
	{
	/**
	 * Variables
	 */
	
	
	
	
	
	/**
	 * Constructeurs
	 */
	public PortList()
		{
		
		}
	
	
	public static String[] getSerialPortList()
		{
		java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
		ArrayList<String> portList = new ArrayList<String>();
		
        while (portEnum.hasMoreElements()) 
        	{
            CommPortIdentifier portIdentifier = portEnum.nextElement();
            
        	if(getPortTypeName(portIdentifier.getPortType()).compareTo("Serial")==0)
        		{
        		portList.add(portIdentifier.getName());
        		}
        	}
        if(portList.size()==0)
        	{
        	return new String[]{}; 
        	}
        else
        	{
        	String[] list = new String[portList.size()];
        	for(int i=0; i<portList.size(); i++)
        		{
        		list[i] = portList.get(i);
        		}
        	return list;
        	}
		}
	
	 private static String getPortTypeName (int portType)
		 {
		 switch (portType)
		 	{
		    case CommPortIdentifier.PORT_I2C:
		        return "I2C";
		    case CommPortIdentifier.PORT_PARALLEL:
		        return "Parallel";
		    case CommPortIdentifier.PORT_RAW:
		        return "Raw";
		    case CommPortIdentifier.PORT_RS485:
		        return "RS485";
		    case CommPortIdentifier.PORT_SERIAL:
		        return "Serial";
		    default:
		        return "unknown type";
			}
		 }

	
	
	
	/*2012*//*RATEL Alexandre 8)*/
	}
